﻿
using System;
using System.Collections.Generic;
using UnityEngine;
using Yoozoo.Mars.Got;

namespace Yoozoo.Core.Common
{
    public class GameObjectParentActiveQualityListener : QualityListenerMono<QualitySetting>
    {
        private HashSet<GameObjectGrading> _particleGradings = new HashSet<GameObjectGrading>();

        
        public override void ChangeQualitySetting(QualitySetting qualitySetting)
        {
            int level = GetLevel(qualitySetting);
            if (_particleGradings!=null)
            {
                foreach (var grading in _particleGradings)
                {
                    if (grading!=null)
                    {
                        grading.ChangeLevel(level);
                    }
                }
            }
        }
        public void AddGameObjectGrading(GameObjectGrading gameObjectGrading)
        {
            if (gameObjectGrading==null) return;
            _particleGradings.Add(gameObjectGrading);
            gameObjectGrading.ChangeLevel(GetLevel(CurrentQualitySetting));
        }
        
        public void RemoveGameObjectGrading(GameObjectGrading gameObjectGrading)
        {
            if(gameObjectGrading==null) return;
            _particleGradings.Remove(gameObjectGrading);
        }
        
        private int GetLevel(QualitySetting qualitySetting)
        {
            int level = 2;
            switch (qualitySetting.Quality)
            {
                case QualityEnum.Low:
                case QualityEnum.Medium:
                    level = 2;
                    break;
                case QualityEnum.High:
                case QualityEnum.VeryHigh:
                    level = 1;
                    break;
                case QualityEnum.Perfect:
                case QualityEnum.PC:
                    level = 0;
                    break;
            }

            return level;
        }
    }
}

